package com.example.administrator.newproject;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import Bean.ShouCang;
import Utils.ImageUtils;

/**
 * Created by aaa on 15-4-22.
 */
public class ShouCangListAdapter extends BaseAdapter {
   Context context;
  List<ShouCang> datas;
    LayoutInflater inflater;
    private FileInputStream in;
    private ByteArrayOutputStream out;

    public ShouCangListAdapter(Context context, List<ShouCang> datas) {
        this.context = context;
        this.datas = datas;
        inflater=LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ShouCangHolder scHolder=null;
        if(convertView==null){
            scHolder=new ShouCangHolder();
            convertView=inflater.inflate(R.layout.shoucang_item,null);
            scHolder.image= (ImageView) convertView.findViewById(R.id.scitem_image);
            scHolder.title= (TextView) convertView.findViewById(R.id.scitem_title);
            convertView.setTag(scHolder);
        }else{
            scHolder= (ShouCangHolder) convertView.getTag();
        }
        ShouCang shouCang = datas.get(position);
        scHolder.title.setText(shouCang.getTitle());
        scHolder.image.setImageResource(R.drawable.ic_launcher);

        String imagepath = shouCang.getImagepath();
        BitmapUtils bitmapUtils = ImageUtils.getBitmapUtils(context);
        bitmapUtils.display(scHolder.image,imagepath);

        return convertView;
    }
    class ShouCangHolder{
       ImageView image;
        TextView title;
    }
}
